﻿/*!
 *  Test
 */

(function () {


    $(function () {
        $("#login").click(function () {

            $("#login").attr("disabled", "disabled");

            $.ajax({
                url: "http://yakool-home.com/backend/login.action",
                method: "POST",
                contentType: "application/x-www-form-urlencoded",
                data: "userName=%E9%99%88%E7%87%95&password=duron900&%E7%99%BB%E5%BD%95=%E6%8F%90%C2%A0%C2%A0%E4%BA%A4",
                statusCode: {
                    302: function (data, status, xhr) {
                        // http://stackoverflow.com/questions/10013812/how-to-prevent-jquery-ajax-from-following-a-redirect-after-a-post
                        alert("302"); // does not work
                    }
                },
                success: function (data, status, xhr) {
                    //alert("success");
                    $.get("http://yakool-home.com/backend/listPurchaseOrders.action?v=0.23445873&sort=purchaseOrderInfo.payupTimestamp&dir=yui-dt-desc&startIndex=0&results=5000&purchaseOrderTrackerName=&buyerName=&certificateMember=&todayPurchaseOrder=&monthPurchaseOrder=&weekPurchaseOrder=&consignDay=&payMode=1,2,3,4,201,10,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130&status=&status1=&mergeType=1,3&createdTimeStart=&createdTimeEnd=&objectId=&payupedTimesStart=&payupedTimesEnd=&salesmanName=&purchaseOrderArea=&department=&isAnolog=0&needPayAmountStart=&needPayAmountEnd=&receiveMode=&noReceiverAddress=&memberType=&memberId=&isTest=2&communityId=&latestConsignTime=&onLineType=1", function (data) {
                        var rs = data.resultsList,
                            len = rs.length,
                            output = 0,
                            income = 0,
                            t;

                        rs.forEach(function (p) {
                            t = p.needPayAmount - p.yakoolCoin;
                            output += p.needPayAmount;
                            income += t;
                        });

                        output = output / 100.0;
                        income = income / 100.0;
                        alert("订单总数: " + len + "\r\n订单总金额: " + output + "\r\n订单总收入: " + income);
                        $("#login").removeAttr("disabled");
                    });
                },
                error: function (xhr, status, error) {
                    alert("error");
                },
                complete: function (xhr, status) {
                    //alert("complete");
                }
            });
        });
    });

}())